package com.cxrj.zhsq.partyMember.controller;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.cxrj.zhsq.annotation.SystemControllerLog;
import com.cxrj.zhsq.partyMember.entity.PartyMemberActivity;
import com.cxrj.zhsq.partyMember.service.PartyMemberActivityService;


@RestController
@RequestMapping("/activity")
public class PartyMemberActivityController {
	
	@Resource
	private PartyMemberActivityService partyMemberActivityService;
	
	/**
	 * 查询所有活动
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "selectActivityPage", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public Map<String, Object> selectActivityPage(HttpServletRequest request, HttpServletResponse response){
		return partyMemberActivityService.selectActivityPage(request,response);
	}
	
	/**
	 * 插入数据
	 * @param partyMemberActivity
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("insertActivity")
	@SystemControllerLog(description = "添加党员活动")
	public Map<String, Object> insertActivity(PartyMemberActivity partyMemberActivity,HttpServletRequest request, HttpServletResponse response){
		try {
			partyMemberActivity.setActivityEndTime(new SimpleDateFormat("yyyy-MM-dd").parse(partyMemberActivity.getActivityEndTimeStr()));
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return partyMemberActivityService.insertActivity(partyMemberActivity,request,response);
	}
	
	/**
	 * 修改数据
	 * @param activityId
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("updateActivity")
	public Map<String, Object> updateActivityState(PartyMemberActivity partyMemberActivity,HttpServletRequest request, HttpServletResponse response){
//		try {
//			partyMemberActivity.setActivityEndTime(new SimpleDateFormat("yyyy-MM-dd").parse(partyMemberActivity.getActivityEndTimeStr()));
//		} catch (ParseException e) {
//			e.printStackTrace();
//		}
		return partyMemberActivityService.updateActivity(partyMemberActivity,request,response);
	}
	
	/**
	 * 根据ID查询
	 * @param activityId
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("selectActivityById")
	public Map<String, Object> selectActivityById(String activityId,HttpServletRequest request, HttpServletResponse response){
		return partyMemberActivityService.selectActivityById(activityId,null,request,response);
	}
	/**
	 * 查看报名
	 * @param activityId
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("selectActivityApply")
	public Map<String, Object> selectActivityApply(String activityId,HttpServletRequest request, HttpServletResponse response){
		return partyMemberActivityService.selectActivityApply(activityId,request,response);
	}

}
